import { defineStore } from 'pinia'
import request from '@/utils/request'
import { ApiRes, bannerItem, BrandItem, HotItem, NewItem, ProductItem, SpecialItem } from '@/types/data'


export default defineStore('home', {
  state() {
      return {
        bannerList: [] as bannerItem[],
        newList: [] as NewItem[],
        hotList: [] as HotItem[],
        brandList: [] as BrandItem[],
        productList: [] as ProductItem[],
        specialList: [] as SpecialItem[]
      }
  },
  actions: {
    async getBannerList() {
      const res = await request.get<ApiRes<bannerItem[]>>('/home/banner')
      this.bannerList = res.data.result      
    },
    async getNewList() {
      const res = await request.get<ApiRes<NewItem[]>>('/home/new')
      this.newList = res.data.result
    },
    async getHotList() {
      const res = await request.get<ApiRes<HotItem[]>>('/home/hot')
      this.hotList = res.data.result
    },
    async getBrandList() {
      const res = await request.get<ApiRes<BrandItem[]>>('/home/brand')
      this.brandList = res.data.result
    },
    async getProductList() {
      const res = await request.get<ApiRes<ProductItem[]>>('/home/goods')
      this.productList = res.data.result
    },
    async getSpecialList() {
      const res = await request.get<ApiRes<SpecialItem[]>>('/home/special')
      // console.log(res);
      this.specialList = res.data.result
    }
  }
})